﻿<UserControl x:Class="MyImdb.Views.SearchView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
             xmlns:converters="clr-namespace:MyImdb.Converters"
             mc:Ignorable="d"
             d:DesignHeight="600"
             d:DesignWidth="800">

    <UserControl.Resources>
        <converters:PosterUrlConverter x:Key="PosterUrl" />
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="42" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <StackPanel x:Name="SearchPanel"
                    Margin="132.5,3.5"
                    Orientation="Horizontal"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Height="35"
                    Width="535">
            <TextBox HorizontalAlignment="Center"
                     VerticalAlignment="Center"
                     Text="{Binding SearchText, Mode=TwoWay}"
                     Controls:TextboxHelper.Watermark="Find Movies, TV shows, Games and more..."
                     Controls:TextboxHelper.ClearTextButton="True"
                     KeyDown="SearchByKeyboardEnter"
                     Width="500" />
            <Button Style="{DynamicResource MetroCircleButtonStyle}"
                    Height="35"
                    Width="35"
                    Command="{Binding SearchCommand}"
                    VerticalAlignment="Top">
                <Rectangle Width="15"
                           Height="15">
                    <Rectangle.Fill>
                        <VisualBrush Stretch="Fill"
                                     Visual="{StaticResource appbar_magnify}" />
                    </Rectangle.Fill>
                </Rectangle>
            </Button>
        </StackPanel>
        
        <Grid x:Name="ResultPanel"
              Margin="0"
              Grid.Row="1">
            <ListBox Margin="0"
                     x:Name="SearchList"
                     ItemsSource="{Binding SearchResult}"
                     SelectedItem="{Binding SelectedImdbItem, Mode=TwoWay}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="10">
                            <Controls:ProgressRing IsActive="True"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center" />
                            <Image Width="200"
                                   Height="300"
                                   Source="{Binding Poster, Converter={StaticResource PosterUrl}}" />
                            <Button Style="{DynamicResource MetroCircleButtonStyle}"
                                    Height="35"
                                    Width="35"
                                    Click="DownloadClick"
                                    VerticalAlignment="Bottom"
                                    HorizontalAlignment="Left">
                                <Rectangle Width="15"
                                           Height="15">
                                    <Rectangle.Fill>
                                        <VisualBrush Stretch="Fill"
                                                     Visual="{StaticResource appbar_download}" />
                                    </Rectangle.Fill>
                                </Rectangle>
                            </Button>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>

                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal"
                                   MaxWidth="1200" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </ListBox>

            <Grid VerticalAlignment="Bottom"
                  HorizontalAlignment="Stretch"
                  Background="Red">
                <TextBlock FontSize="12"
                           FontWeight="Bold"
                           Foreground="White"
                           HorizontalAlignment="Center"
                           Text="{Binding InfoText}" />
            </Grid>



        </Grid>

        <Grid x:Name="LoadingGrid"
              Visibility="{Binding LoadingVisibility}"
              Grid.RowSpan="2"
              Background="#7F000000"
              d:IsHidden="True">
            <StackPanel Margin="0"
                        Orientation="Vertical"
                        Background="White"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center">
                <Controls:ProgressRing HorizontalAlignment="Center"
                                       VerticalAlignment="Center"
                                       IsActive="True"
                                       
                                       Foreground="Red"
                                       Width="60"
                                       Height="60" />
                <TextBlock TextWrapping="Wrap"
                           Text="Loading, please wait ..."
                           Foreground="Red"
                           FontSize="18.667"
                           Margin="0,8,0,0" />
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>
